using System;
using NUnit.Framework;

namespace PropertyExpression.ControllableQuery.Test
{
    [TestFixture]
    public class DemoTest
    {
        [Test]
        public void Test1()
        {
            foreach (var reader in MainTest.ExecuteReader(
                context => GetModelPublications1(
                    context.CreateParam("ModelCode1"),
                    context.CreateParam("ModelSequence1"))))
            {
                Console.WriteLine(
                    "PublicationId = '{0}', ModelCode = '{1}', ModelSequence = '{2}'",
                    reader.Item1(),
                    reader.Item2(),
                    reader.Item3()
                    );
            }
        }

        private static IQuery<Tuple<Guid, NVarChar<L20>, NVarChar<L2>>> GetModelPublications1(IParam<string> modelCode, IParam<string> modelSequence)
        {
            return
(@"SELECT
    ModelPublication.PublicationId AS Item1,
    ModelPublication.ModelCode AS Item2,
    ModelPublication.ModelSequence AS Item3
FROM
    ModelPublication
WHERE
    ModelPublication.ModelCode = " + modelCode + @"
    AND ModelPublication.ModelSequence = " + modelSequence).ToQuery<Tuple<Guid, NVarChar<L20>, NVarChar<L2>>>();
        }

        [Test]
        public void Test2()
        {
            foreach (var reader in MainTest.ExecuteReader(
                context => GetModelPublications2(
                    context.CreateParam("ModelCode1"),
                    context.CreateParam("ModelSequence1"))))
            {
                Console.WriteLine(
                    "PublicationId = '{0}', ModelCode = '{1}', ModelSequence = '{2}'",
                    reader.PublicationId(),
                    reader.ModelCode(),
                    reader.ModelSequence()
                    );
            }
        }

        private static IQuery<IModelPublicationInfo> GetModelPublications2(IParam<string> modelCode, IParam<string> modelSequence)
        {
            return
(@"SELECT
    ModelPublication.PublicationId,
    ModelPublication.ModelCode,
    ModelPublication.ModelSequence
FROM
    ModelPublication
WHERE
    ModelPublication.ModelCode = " + modelCode + @"
    AND ModelPublication.ModelSequence = " + modelSequence).ToQuery<IModelPublicationInfo>();
        }
    }

    public interface IModelPublicationInfo
    {
        Guid PublicationId { get; }
        NVarChar<L20> ModelCode { get; }
        NVarChar<L2> ModelSequence { get; }        
    }
}